package com.wx.cloud.daily.controller;

import com.wx.cloud.daily.common.CommonResult;
import com.wx.cloud.daily.model.Daily;
import com.wx.cloud.daily.model.Page;
import com.wx.cloud.daily.service.DailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/daily")
public class DailyController {

    @Autowired
    private DailyService dailyService;

    @GetMapping("/getMyDailyList")
    public CommonResult getMyDailyList(@RequestParam Map<String, Object> data){
        HashMap<String, Object> map = new HashMap<>();
        List<Daily> dailies = dailyService.getMyDailyList(data);
        int count = dailyService.getMyDailyCount(data);
        Page page = new Page();
        page.setList(dailies);
        page.setTotal(count);
        map.put("list",dailies);
        map.put("count",count);
        return CommonResult.success(map);
    }

    @GetMapping("/getSelectList")
    public CommonResult getSelectList(@RequestParam Map<String, Object> data){
        HashMap<String, Object> map = new HashMap<>();
        List<Daily> dailies = dailyService.getSelectList(data);
        int count = dailyService.getSelectCount(data);
        Page page = new Page();
        page.setList(dailies);
        page.setTotal(count);
        map.put("list",dailies);
        map.put("count",count);
        return CommonResult.success(map);
    }

    @GetMapping("/getDailyById")
    public CommonResult getDailyById(@RequestParam Integer id){
        HashMap<String, Object> map = new HashMap<>();
        Daily daily = dailyService.getDailyById(id);
        map.put("data",daily);
        return CommonResult.success(map);
    }

    @PostMapping("/saveDaily")
    public CommonResult saveDaily(@RequestBody Daily daily){
        HashMap<String, String> map = new HashMap<>();
        String result = dailyService.saveDaily(daily);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/submitDaily")
    public CommonResult submitDaily(@RequestBody Daily daily){
        HashMap<String, String> map = new HashMap<>();
        String result = dailyService.submitDaily(daily);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/saveCheckDaily")
    public CommonResult saveCheckDaily(@RequestBody Daily daily){
        HashMap<String, Integer> map = new HashMap<>();
        int result = dailyService.saveCheckDaily(daily);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/submitCheckDaily")
    public CommonResult submitCheckDaily(@RequestBody Daily daily){
        HashMap<String, Integer> map = new HashMap<>();
        int result = dailyService.submitCheckDaily(daily);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/checkDaily")
    public CommonResult checkDaily(@RequestBody Daily daily){
        HashMap<String, Integer> map = new HashMap<>();
        int result = dailyService.checkDaily(daily);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/createWord")
    public CommonResult createWord(@RequestBody Daily daily){
        dailyService.createWord(daily);
        return CommonResult.success("ok");
    }

    @PostMapping("/delDaily")
    public CommonResult delDaily(@RequestBody Daily daily){
        HashMap<String, Integer> map = new HashMap<>();
        int result = dailyService.delDaily(daily);
        map.put("result",result);
        return CommonResult.success(map);
    }

    @PostMapping("/batchDeletion")
    public CommonResult batchDeletion(@RequestParam List<Integer> ids){
        HashMap<String, Object> map = new HashMap<>();
        String result = dailyService.batchDeletion(ids);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/createDeletion")
    public CommonResult createDeletion(@RequestParam List<Integer> ids){
      dailyService.createDeletion(ids);
      return CommonResult.success("ok");
    }

}
